home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUT1-9.ZIP / TUTPROG4.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-11  |  7KB  |  199 lines

  1. {$X+}   (* This is a handy little trick to know. If you put this at the top
  2.            of your program, you do not have to set a variable when calling
  3.            a function, i.e. you may just say 'READKEY' instead of
  4.            'CH:=READKEY'                                                *)
  5.  
  6. USES Crt;           (* This has a few nice functions in it, such as the
  7.                        READKEY command.                                 *)
  8.  
  9. CONST VGA = $a000;  (* This sets the constant VGA to the segment of the
  10.                        VGA screen.                                      *)
  11.  
  12. Type Virtual = Array [1..64000] of byte;  { The size of our Virtual Screen }
  13.      VirtPtr = ^Virtual;                  { Pointer to the virtual screen }
  14.  
  15. VAR Virscr : VirtPtr;                      { Our first Virtual screen }
  16.     Vaddr  : word;                        { The segment of our virtual screen}
  17.  
  18.  
  19. {──────────────────────────────────────────────────────────────────────────}
  20. Procedure SetMCGA;  { This procedure gets you into 320x200x256 mode. }
  21. BEGIN
  22.   asm
  23.      mov        ax,0013h
  24.      int        10h
  25.   end;
  26. END;
  27.  
  28.  
  29. {──────────────────────────────────────────────────────────────────────────}
  30. Procedure SetText;  { This procedure returns you to text mode.  }
  31. BEGIN
  32.   asm
  33.      mov        ax,0003h
  34.      int        10h
  35.   end;
  36. END;
  37.  
  38.  
  39. {──────────────────────────────────────────────────────────────────────────}
  40. Procedure Cls (Col : Byte; Where:Word);
  41.    { This clears the screen to the specified color, on the VGA or on the
  42.         virtual screen }
  43. BEGIN
  44.   Fillchar (Mem [where:0],64000,col);
  45. END;
  46.  
  47. {──────────────────────────────────────────────────────────────────────────}
  48. procedure WaitRetrace; assembler;
  49.   { This waits until you are in a Verticle Retrace ... this means that all
  50.     screen manipulation you do only appears on screen in the next verticle
  51.     retrace ... this removes most of the "fuzz" that you see on the screen
  52.     when changing the pallette. It unfortunately slows down your program
  53.     by "synching" your program with your monitor card ... it does mean
  54.     that the program will run at almost the same speed on different
  55.     speeds of computers which have similar monitors. In our SilkyDemo,
  56.     we used a WaitRetrace, and it therefore runs at the same (fairly
  57.     fast) speed when Turbo is on or off. }
  58.  
  59. label
  60.   l1, l2;
  61. asm
  62.     mov dx,3DAh
  63. l1:
  64.     in al,dx
  65.     and al,08h
  66.     jnz l1
  67. l2:
  68.     in al,dx
  69.     and al,08h
  70.     jz  l2
  71. end;
  72.  
  73.  
  74.  
  75.  
  76. {──────────────────────────────────────────────────────────────────────────}
  77. Procedure SetUpVirtual;
  78.    { This sets up the memory needed for the virtual screen }
  79. BEGIN
  80.   GetMem (VirScr,64000);
  81.   vaddr := seg (virscr^);
  82. END;
  83.  
  84.  
  85. {──────────────────────────────────────────────────────────────────────────}
  86. Procedure ShutDown;
  87.    { This frees the memory used by the virtual screen }
  88. BEGIN
  89.   FreeMem (VirScr,64000);
  90. END;
  91.  
  92.  
  93. {──────────────────────────────────────────────────────────────────────────}
  94. Procedure PutPixel (X,Y : Integer; Col : Byte; Where : Word);
  95.    { This puts a pixel at X,Y using color col, on VGA or the Virtual Screen}
  96. BEGIN
  97.   Mem [Where:X+(Y*320)]:=col;
  98. END;
  99.  
  100.  
  101. {──────────────────────────────────────────────────────────────────────────}
  102. Procedure Flip;
  103.    { This flips the virtual screen to the VGA screen. }
  104. BEGIN
  105.   Move (Virscr^,mem [VGA:0],64000);
  106. END;
  107.  
  108. {──────────────────────────────────────────────────────────────────────────}
  109. Procedure BlockMove;
  110.    { This tests various ways of moving a block around the screen }
  111. VAR loop1,loop2,loop3:Integer;
  112. BEGIN
  113.   For loop1:=1 to 50 do BEGIN                     { This draw a block    }
  114.     for loop2:=1 to 50 do                         {  directly to VGA, no }
  115.       for loop3:=1 to 50 do                       {  flipping            }
  116.         putpixel (loop1+loop2,loop3,32,VGA);
  117.     cls (0,VGA);
  118.   END;
  119.  
  120.   For loop1:=1 to 50 do BEGIN                     { This draws a block     }
  121.     for loop2:=1 to 50 do                         { to the virtual screen, }
  122.       for loop3:=1 to 50 do                       { then flips it to VGA   }
  123.         putpixel (loop1+loop2,loop3,32,Vaddr);
  124.     flip;
  125.     cls (0,Vaddr);
  126.   END;
  127.  
  128.   For loop1:=1 to 50 do BEGIN                     { This draws a block     }
  129.     for loop2:=1 to 50 do                         { to the virtual screen, }
  130.       for loop3:=1 to 50 do                       { waits for a retrace,   }
  131.         putpixel (loop1+loop2,loop3,32,Vaddr);    { then flips it to VGA   }
  132.     waitretrace;
  133.     flip;
  134.     cls (0,Vaddr);
  135.   END;
  136. END;
  137.  
  138.  
  139. {──────────────────────────────────────────────────────────────────────────}
  140. Procedure PatternDraw;
  141.    { This test the speed of flipping by drawing two patterns and flipping
  142.      them }
  143. VAR loop1,loop2:integer;
  144. BEGIN
  145.   for loop1:=1 to 100 do                        { This draws pattern one }
  146.     for loop2:=1 to 100 do                      { to the virtual screen  }
  147.       putpixel (loop1,loop2,loop1,Vaddr);       { then flips it to VGA   }
  148.   flip;
  149.  
  150.   for loop1:=1 to 100 do                        { This draws pattern two }
  151.     for loop2:=1 to 100 do                      { to the virtual screen  }
  152.       putpixel (loop1,loop2,loop2,Vaddr);       { then flips it to VGA   }
  153.   flip;
  154. END;
  155.  
  156.  
  157. BEGIN
  158.   ClrScr;
  159.   Writeln ('This program will demonstrate the power of virtual screens.');
  160.   Writeln ('A block will firstly move across the screen, being drawn and');
  161.   Writeln ('erased totally on the VGA. Then the same block will move');
  162.   Writeln ('across, but will be drawn on the virtual screen and flipped');
  163.   Writeln ('to the VGA screen without a retrace (see part 2). The the');
  164.   Writeln ('block will go again, with flipping and a retrace.');
  165.   Writeln;
  166.   Writeln ('I will then draw a pattern, flip it to VGA, draw another');
  167.   Writeln ('pattern, flip it to VGA, and repeat that until a key is pressed.');
  168.   Writeln ('This will demonstrate that even when I put down 10000 pixels,');
  169.   Writeln ('then flip them to the VGA, it is still relatively fast.      ');
  170.   Writeln; Writeln;
  171.   Writeln ('Hit any key to continue ...');
  172.   readkey;
  173.   setmcga;
  174.   setupvirtual;
  175.   cls (0,vaddr);    { After you have got the memory for the virtual screen,
  176.                       it is usually filled with random garbage. It is always
  177.                       wise to clear the virtual screen directly afterwards }
  178.   BlockMove;
  179.  
  180.   Repeat
  181.     PatternDraw;
  182.   Until keypressed;
  183.  
  184.   Readkey;
  185.   settext;
  186.   shutdown;
  187.   Writeln ('All done. This concludes the fourth sample program in the ASPHYXIA');
  188.   Writeln ('Training series. You may reach DENTHOR under the name of GRANT');
  189.   Writeln ('SMITH on the MailBox BBS, or leave a message to ASPHYXIA on the');
  190.   Writeln ('ASPHYXIA BBS. Get the numbers from Roblist, or write to :');
  191.   Writeln ('             Grant Smith');
  192.   Writeln ('             P.O. Box 270');
  193.   Writeln ('             Kloof');
  194.   Writeln ('             3640');
  195.   Writeln ('I hope to hear from you soon!');
  196.   Writeln; Writeln;
  197.   Write   ('Hit any key to exit ...');
  198.   Readkey;
  199. END.